<?php

defined('__MAPEXEC__') or die('No direct access allowed');

/**
 * Abstract base class for all classes which export map data.
 */
abstract class Maps_Export_Common {
  
  protected $apiKeyRequired = false;
  
  /**
   * Escapes a string of text.
   * @param   String  The string to escape
   * @param   String  Optional type of escaping to use. Default is "javascript".
   * @return  String  The escaped string
   */
  protected function escape($str, $type='javascript') {
    if ($type == 'html') {
      $str = preg_replace('/&/','&amp;',$str);
      $str = preg_replace('/"/','&quote;',$str);
      $str = preg_replace('/>/','&gt;',$str);
      $str = preg_replace('/</','&lt;',$str);
    } else {
      $str = preg_replace('/"/', '\"', $str);
    }
    return $str;
  }
  
  /**
   * Detects whether or not this export type requires an API Key.
   * @param   void
   * @return  boolean   True if a key is required, false otherwise.
   */
  public function requiresAPIKey() {
    return $this->apiKeyRequired;
  }
  
  /**
   * Abstract function which renders map data in a format.
   * Defined by implementing classes.
   */
  abstract public function render(Maps_Map_Common $map, Maps_Icon_Manager_Common $iconManager = null);
  
}
?>